<?php	include_once('../config/db.php');
		include_once('../functions/student.php');
if(!isset($_SESSION['e_logged_in'])) 
header('location:login.php');
if(isset($_REQUEST['add'])){
	$arr=array();
	$user=$_REQUEST['user'];
	$name=$_REQUEST['name'];
	$contact=$_REQUEST['contact'];
	$email=$_POST['email'];
	$pass=$_REQUEST['user'];

	if($_REQUEST['user']=='' && $_REQUEST['name']=='' && $_REQUEST['contact']=='' && $_REQUEST['email']==''){
		$empty=TRUE;
	}
	elseif(!is_numeric($contact)){
		$notnumber=TRUE;
	}
	elseif(verify_student($user)==$user){
		$check_id=TRUE;
	}
	elseif(verify_contact($contact)==$contact){
		$check_contact=TRUE;
	}
	elseif(verify_email($email)==$email){
		$check_email=TRUE;
	}
	elseif(is_numeric($name)){
		$notname=TRUE;}
	elseif(!preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email'])){
		$notemail=TRUE;
		}
		else
			$insert=reg_student( $_REQUEST['user'], $_REQUEST['name'], $_REQUEST['contact'],$_REQUEST['email']);
			$register=TRUE;
		}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../style.css" type="text/css"/>
<title>Online Reservation System</title>
</head>

<body>
<div id="header">
<div id="logo">
  <p>&nbsp;</p>
  <div id="apDiv1"><img src="../image/logo.png" alt="" width="500" height="100" /></div>
  <p>&nbsp;</p>
</div>

</div>
<div id="con-body">
<?php include 'navigation.php';?>
  <?php if(isset($empty)):?>
 <div id="error">You must enter values</div>
<?php elseif(isset($check_id)): ?>
<div id="error">ID number already exist</div>
<?php elseif(isset($notnumber)):?>
<div id="error">This is not a number</div>
<?php elseif(isset($check_contact)):?>
<div id="error">Contact number already exist.</div>
<?php elseif(isset($check_email)):?>
<div id="error">Email address already exist.</div>
<?php elseif(isset($notname)):?>
<div id="error">You enter an invalid credentials</div>
<?php elseif(isset($notemail)):?>
<div id="error">You enter an invalid email address</div>
<?php elseif(isset($register)):?>
<div id="success">Registered. </div>
<!--<META HTTP-EQUIV='Refresh' CONTENT='1; URL=index.php'>-->
<?php endif;?>

<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  <table width="647" border="0">
    <tr>
      <td width="92">Student no: </td>
      <td width="539"><input name="user" type="text" id="user" size="40" /></td>
    </tr>
    <tr>
      <td>Name:</td>
      <td><input name="name" type="text" id="name" size="40" /></td>
    </tr>
    <tr>
      <td>Contact #:</td>
      <td><input name="contact" type="text" id="contact" size="40" /></td>
    </tr>
    <tr>
      <td>Email address:</td>
      <td><input name="email" type="text" id="email" size="40" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="add" type="submit" class="blue" id="add" value="Add Student" /></td>
    </tr>
</table>
</form></div>
</body>
</html>